package Core;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import Engine.GameComponents.Entity;
import Engine.Utils.Vector2f;

/**
 * 
 * @author Lueko
 *
 */
public class Mob extends Entity {
    
    protected BufferedImage[] images;
    protected boolean animating;
    protected int activeImage = 0;
    protected int counter = 0;
    protected int frameTime = 30;

    /**
     * @param pos Position of the entity.
     * @param images Images of the mob animation.
     * @param solid Defines whether a mob can collide.
     * @param animating Defines whether a mob shall run the animation. 
     */
    public Mob(Vector2f pos, BufferedImage[] images, boolean solid, boolean animating) {
        super(pos, solid);
        this.images = images;
        this.image = images[0];
        this.animating = animating;
    }
    
    @Override
    public void tick() {
        if (animating) animate();
    }
    
    @Override
    public void render(Graphics g) {
        g.drawImage(image, (int) (pos.getX() - Core.getMapPos().getX()), (int) (pos.getY() - Core.getMapPos().getY()), null);
    }
    
    protected void animate() {
        if (counter > frameTime) {
            if (activeImage < images.length - 1) {
                activeImage++;
                image = images[activeImage];
            } else {
                activeImage = 0;
                image = images[activeImage];
            }
            counter = 0;
        }
        counter++;
    }

    public BufferedImage[] getImages() {
        return images;
    }

    public void setImages(BufferedImage[] images) {
        this.images = images;
    }

    public boolean isAnimating() {
        return animating;
    }

    public void setAnimating(boolean animating) {
        this.animating = animating;
    }

    public int getActiveImage() {
        return activeImage;
    }

    public void setActiveImage(int activeImage) {
        this.activeImage = activeImage;
    }

    public int getCounter() {
        return counter;
    }

    public void setCounter(int counter) {
        this.counter = counter;
    }

    public int getFrameTime() {
        return frameTime;
    }

    public void setFrameTime(int frameTime) {
        this.frameTime = frameTime;
    }

}
